package cn.drenal.capcap.controller.forum;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.drenal.capcap.common.Response;
import cn.drenal.capcap.entity.Activity;
import cn.drenal.capcap.entity.Artwork;
import cn.drenal.capcap.entity.ArtworkImage;
import cn.drenal.capcap.entity.Banner;
import cn.drenal.capcap.entity.Comment;
import cn.drenal.capcap.entity.vo.ArtworkDetailVO;
import cn.drenal.capcap.service.ActivityService;
import cn.drenal.capcap.service.ArtworkService;
import cn.drenal.capcap.service.BannerService;
import cn.drenal.capcap.service.CommentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前台轮播图控制器
 */
@RestController
@RequestMapping("/forum/banner")
@RequiredArgsConstructor
public class ForumBannerController {

    private final BannerService bannerService;

    private final ArtworkService artworkService;

    private final ActivityService activityService;

    /**
     * 获取首页轮播图列表
     *
     * @return 启用状态的轮播图列表
     */
    @SaIgnore
    @GetMapping("/list")
    public Response<List<Banner>> list() {
        return Response.success(bannerService.getEnabledBanners());
    }

    /**
     * 获取轮播图关联的作品详情
     *
     * @param artworkId 作品ID
     * @return 作品详情
     */
    @SaIgnore
    @GetMapping("/artwork/{artworkId}")
    public Response<ArtworkDetailVO> getArtworkDetail(@PathVariable Long artworkId) {
        return Response.success(artworkService.getArtworkDetailById(artworkId));
    }

    /**
     * 点赞作品
     *
     * @param artworkId 作品ID
     * @return 操作结果
     */

    @PostMapping("/artwork/{artworkId}/like")
    public Response<Void> likeArtwork(@PathVariable Long artworkId) {
        Artwork artwork = artworkService.getById(artworkId);
        if (artwork != null) {
            artworkService.lambdaUpdate()
                    .eq(Artwork::getId, artworkId)
                    .setSql("favorite_count = favorite_count + 1")
                    .update();
        }
        return Response.success();
    }

    /**
     * 获取轮播图关联的活动详情
     *
     * @param activityId 活动ID
     * @return 活动详情
     */
    @SaIgnore
    @GetMapping("/activity/{activityId}")
    public Response<Activity> getActivityDetail(@PathVariable Long activityId) {
        return Response.success(activityService.getById(activityId));
    }
}